import java.util.Scanner;

public class FinalCode {

	public static void main(String[] args) {
		int answer;
		int count = 0;
		String userInput;
		int max = 100;
		int min = 1;
		answer = (int) (Math.random()*100)+1;
		boolean flag = true;
		Scanner sc = new Scanner(System.in);
		
		while(flag){
			System.out.printf("輸入 %d ~ %d 之間的值 \n" ,min,max );
			userInput = sc.next();
			int input = -1;
			try{
				input = Integer.parseInt(userInput);
			}
			catch(Exception ex){
				System.out.printf("請輸入數字");
			}
			count++;
			if (answer == input){
				System.out.printf("正確! 答案為 %d 使用次數:%d",answer,count);
				flag = false;
			}
			else{
				if (input<answer && input >= min){
					min = input+1;
					}
				if (input > answer && input <= max){
					max = input-1;
					}
				}
			}
			
		}
	}

